package mng
{
	public class TurnMng
	{
		public var oParent:*;
		[Bindable] public var whoTurn:String;
		public var isReady:Boolean = false;
		
		public function TurnMng(o:*)
		{
			oParent = o;
		}
		public function readyTile():void {
			isReady = true;
			oParent.txtStatus.text = PluginConstants.iStartTileLen +'tile selected..';
			
			if(oParent.isMyTurn == true) {
				isTurn = PluginConstants.READY;
				oParent.txtStatus.text = 'wait for opponent ready';
			} else {
				isTurn = PluginConstants.READY;
				oParent.txtStatus.text = 'you have to soring tile.. and click ready button';
			}
		}

		// server에서 ready응답이 왔을경우
		public function readyProcTile():void {			
			if(oParent.isMyTurn == true) {
				isTurn = PluginConstants.ME;
				oParent.txtStatus.text = 'get one more tile';
			} else {
				isTurn = PluginConstants.OPPONENT;
				oParent.txtStatus.text = 'wait for opponent action';
			}
		}
		
		public function set isTurn(s:String):void {
			oParent.txtIsturn.text = s;
			
			whoTurn = s;
			if(PluginConstants.ME == s ) {
				oParent.hbOppent.enabled = false;
				oParent.hbMe.mouseChildren = true;
				oParent.hbBack.enabled = true;
				oParent.vbWhite.enabled = true;				
			} 
			// 최초 상대 ready버튼 대기 
			else if(PluginConstants.READY == s){
				oParent.hbBack.enabled = false;
				oParent.hbOppent.enabled = false;
			}
			// 내턴에서 타일 가져왔을시 
			else if(PluginConstants.ME_SELECTED == s){
				oParent.hbOppent.enabled = true;
				oParent.hbMe.mouseChildren = true;
				oParent.hbBack.enabled = false;
				oParent.vbWhite.enabled = true;
				oParent.txtStatus.text = 'you have to select opponent tile';
			}			
			else if(PluginConstants.ALL == s){
				oParent.hbOppent.enabled = false;
				oParent.hbMe.mouseChildren = true; //
				oParent.hbBack.enabled = true;
				oParent.vbWhite.enabled = true;
			}
			else if(PluginConstants.OPPONENT == s){
				oParent.hbOppent.enabled = false;
				oParent.hbMe.mouseChildren = false;
				oParent.hbBack.enabled = false;
				//oParent.vbWhite.enabled = false;
			}
			
		}
		
		public function get isTurn():String {
			return whoTurn;
		}
	}
}